﻿/**
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.thorqq.magictimer;

//import com.android.deskclock2.R;

import com.thorqq.magictimer.util.Util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class Configuration
{
    //是否第一次启动
    private final String KEY_FIRST_START = "first_start";
    private final boolean DEFAULT_FIRST_START = true;

    private SharedPreferences mSettings;
    private Editor mEditor;
    private Context mContext;
    static private Configuration mInstance = new Configuration();
    
    static public Configuration getIntance()
    {
        return mInstance;
    }

    //初始化
    public boolean init(Context context)
    {
        mContext = context; 

        mSettings = PreferenceManager.getDefaultSharedPreferences(mContext); 
        if(mSettings == null){
            return false;
        }
        
        mEditor = mSettings.edit();
        if(mEditor == null){
            return false;
        }
                
        return true;
    }

    //是否第一次启动
    public boolean isFirstStart()
    {
        return mSettings.getBoolean(KEY_FIRST_START, DEFAULT_FIRST_START);
    }  
    
    public void setFirstStart()
    {
        mEditor.putBoolean(KEY_FIRST_START, false);   
        mEditor.commit(); 
    }
    
    //是否检查更新
    public boolean isCheckUpdate()
    {
        return mSettings.getBoolean(ConfigurationActivity.KEY_CHECK_UPDATE_FLAG, 
                ConfigurationActivity.DEFAULT_CHECK_UPDATE_FLAG);
    }
    
    public void setCheckUpdate(boolean b)
    {
        mEditor.putBoolean(ConfigurationActivity.KEY_CHECK_UPDATE_FLAG, b);   
        mEditor.commit(); 
    }
    
    //贪睡时间
    public int getSnoozeDuration()
    {
        return Util.strToInt(mSettings.getString(ConfigurationActivity.KEY_ALARM_SNOOZE, 
                ConfigurationActivity.DEFAULT_SNOOZE_MINUTE));
    }

    //侧边按钮功能
    public int getVolumeBehavior()
    {
        return Util.strToInt(mSettings.getString(ConfigurationActivity.KEY_VOLUME_BEHAVIOR, 
                ConfigurationActivity.DEFAULT_VOLUME_BEHAVIOR));
    }

    //闹铃持续时间
    public int getAlarmTimeout()
    {
        return Util.strToInt(mSettings.getString(ConfigurationActivity.KEY_ALARM_TIMEOUT_SECONDS, 
                ConfigurationActivity.DEFAULT_ALARM_TIMEOUT_SECONDS));
    }

    //调测开关
    public boolean getDebugFlag()
    {
        return mSettings.getBoolean(ConfigurationActivity.KEY_DEBUG_FLAG, 
                ConfigurationActivity.DEFAULT_DEBUG_FLAG);
    }

    //日志保存的最大条数
    public int getTimerLogNum()
    {
        //TODO
        return 30;
    }

}
